﻿namespace OasisCiq.Tests.Resources
{
    using System.IO;
    using System.Reflection;

    public static class XmlFiles
    {
        private static readonly Assembly Assembly = typeof(XmlFiles).Assembly;
        private static readonly string ResourcePrefix = typeof(XmlFiles).Namespace;

        public static string GetXml(string dir, string name)
        {
            var rn = string.Format("{0}.{1}.{2}.xml", ResourcePrefix, dir, name);
            using (var stream = Assembly.GetManifestResourceStream(rn))
            {
                if (stream == null)
                {
                    return null;
                }

                using (var reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
        }

        public static string GetSchema(string name)
        {
            var rn = string.Format("{0}.Xsd.{1}.xsd", ResourcePrefix, name);
            using (var stream = Assembly.GetManifestResourceStream(rn))
            {
                if (stream == null)
                {
                    return null;
                }

                using (var reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
        }
    }
}